package com.manager.plat.util;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;

public class BaseFiter implements Filter {
	private static Logger logger = Logger.getLogger(BaseFiter.class);
	@Override
	public void destroy() {
		logger.info("进入摧毁");
	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
		if(request instanceof HttpServletRequest) {
			HttpServletRequest httpRequest = (HttpServletRequest) request;
			/**获取ContextPath，放到request里面方便EL使用*/
			String path = httpRequest.getContextPath();
			request.setAttribute("path",path);
			logger.info(String.format("把[%s]放入request", path));
		}
		chain.doFilter(request, response);
	}

	@Override
	public void init(FilterConfig arg0) throws ServletException {
		logger.info("进入初始化方法");
	}
}
